<?php
/* @var $this OrderAdminController */
/* @var $data DndBoxanhfoodOrder */
?>

<div class="view">
    <?php $data->scenario = 'admin'; ?>
	<b><?php echo CHtml::encode($data->getAttributeLabel('order_id')); ?>:</b>
	<?php echo CHtml::link('#'.CHtml::encode($data->order_id), array('view', 'id'=>$data->id)); ?>
	<br />

	<b><?php echo CHtml::encode($data->getAttributeLabel('name')); ?>:</b>
	<?php echo CHtml::encode($data->name); ?>
	<br />

	<b><?php echo CHtml::encode($data->getAttributeLabel('email')); ?>:</b>
	<?php echo CHtml::encode($data->email); ?>
	<br />

	<b><?php echo CHtml::encode($data->getAttributeLabel('phone')); ?>:</b>
	<?php echo CHtml::encode($data->phone); ?>
	<br />

	<b><?php echo CHtml::encode($data->getAttributeLabel('payment_type')); ?>:</b>
	<?php echo CHtml::encode(( $data->payment_type == 0 ? 'Thanh toán khi giao hàng' : 'Chuyển khoản')); ?>
	<br />
	
	<b><?php echo CHtml::encode($data->getAttributeLabel('dia_chi_giao_hang')); ?>:</b>
	<?php echo CHtml::encode($data->dia_chi_giao_hang); ?>
	<br />
	
	<b><?php echo CHtml::encode($data->getAttributeLabel('dia_chi_khach_hang')); ?>:</b>
	<?php echo CHtml::encode($data->dia_chi_khach_hang); ?>
	<br />
	
	<b><?php echo CHtml::encode($data->getAttributeLabel('description')); ?>:</b>
	<?php echo CHtml::encode($data->description); ?>
	<br />
	
	<b><?php echo CHtml::encode($data->getAttributeLabel('status')); ?>:</b>
	<?php echo CHtml::encode(($data->status == 0 ? 'Đơn hàng chưa xử lí' : ($data->status == 1 ? 'Đơn hàng đã được xử lí' : 'Đơn hàng hủy hoặc lỗi'))); ?>
	<br />
	
    <b><?php echo CHtml::encode($data->getAttributeLabel('creation_datetime')); ?>:</b>
	<?php echo CHtml::encode($data->creation_datetime); ?>
	<br />
	<b>Chi tiết đơn hàng:</b>
	<?php 
		$oderDetail = OrderDetail::model()->findAll("order_id='".$data->id."'");
	?>
	<div class="CSSTableGenerator" >
                <table >
                    <tr>
                        <td>
                            STT
                        </td>
                        <td >
                            Sản phẩm
                        </td>
                        <td>
                            Giá đơn vị
                        </td>
						<td>
                            Số lượng
                        </td>
						<!--td>
                            Thành tiền
                        </td>
						<td>
                            Phí vận chuyển
                        </td-->
						<td>
                            Tổng cộng
                        </td>
                    </tr>
					<?php $i = 1;$sl = 0; $thanh_tien = 0; $phi = 0;$total = 0; ?>
					<?php foreach($oderDetail as $item ): ?>
						<tr>
							<td><?php echo $i++; ?></td>
							<?php $product = Product::model()->findAll("id='".$item->product_id."'"); ?>
							<td><?php echo CHtml::link(CHtml::encode($product[0]->name),array('admin/productadmin/view', 'id'=>$product[0]->id),array('target' => '_blank'));  ?></td>
							<td><?php echo number_format($product[0]->on_sale,0); ?></td>
							<td><?php echo $item->quantity; ?></td>
							<!--td><?php echo number_format($item->price,0); ?></td>
							<td><?php echo number_format($item->shipping_cost,0); ?></td-->
							<td><?php echo number_format($item->price*$item->quantity + $item->shipping_cost,0); ?></td>
							<?php $sl += $item->quantity; $thanh_tien += $item->price; $phi = $item->shipping_cost;$total += ($item->price*$item->quantity + $item->shipping_cost); ?>
						</tr>
					<?php endforeach; ?>
						<tr>
							<td colspan="3">Tổng cộng</td>
							<td><?php echo number_format($sl,0); ?></td>
							<!--td><?php echo number_format($thanh_tien,0).' VNĐ'; ?></td>
							<td><?php echo number_format($phi,0).' VNĐ'; ?></td-->
							<td><?php echo number_format($total,0).' VNĐ'; ?></td>
						</tr>
                </table>
	</div>

</div>